/**
 * 
 */
package com.jm.web.tags;

import com.jm.utils.AttributeBuilder;
import com.jm.utils.StringHelper;
import com.jm.utils.htmlNode.XmlNode;
import com.jm.web.builder.ExportBuilder;
import com.jm.web.form.Export;
import com.jm.web.form.support.FormItem;
import com.jm.web.tags.support.BaseTag;

/**
 * @author yanjie
 * Oct 31, 2011 8:39:44 AM
 */
public class ExportTag extends BaseTag{
	
	private static final long serialVersionUID = -8193786048312077950L;
	private Export export = null;
	
	@Override
	public void clear() {
		export = null;
		super.clear();
	}
	
	@Override
	protected int onStartTag() {
		if(this.getPage().isExport() && !this.isEp()){
			return SKIP_BODY;
		}
		
		if(this.getPage().isExportFile())
			return EVAL_BODY_BUFFERED;
		else 
			return super.onStartTag();
		
	}
	
	@Override
	public String getBuilderName() {
		return ExportBuilder.class.getName();
	}
	
	public void setJxl(String strValue) {
		SetExtValue("jxl",strValue);
		
		if(this.GetExtValue("jxl",false) && !this.getPage().isJxl()){
			this.getPage().setJxl(true);
		}
	}
	
	public void setSheetname(String strValue) {
		SetExtValue("sheetname",strValue);
	}
	
	public Export getExportNode(){
	     if(this.export != null)
	    	 return this.export;
	     
	     AttributeBuilder attrs = new AttributeBuilder();
			attrs.InitFromHashtable(this.getExtAttrList(),true);
	    
		export = new Export();
	    export.InitTag(this);
	    FormItem.LoadFromXML(StringHelper.Format("<export %1$s />",attrs.ToOutputString()),export);
        export.init();
        return export;
	}
}
